"""Initial

Revision ID: 224e3fe44bb2
Revises: 
Create Date: 2023-11-27 14:39:18.672731

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "224e3fe44bb2"
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "activation_code",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(length=255), nullable=False),
        sa.Column("limit", sa.Integer(), server_default="0", nullable=False),
        sa.Column("reusable", sa.Boolean(), server_default="0", nullable=False),
        sa.Column("uses_number", sa.Integer(), server_default="0", nullable=False),
        sa.Column(
            "subscription_type",
            sa.Enum(
                "one_calendar", "seven_calendars", "unlimited", name="subscriptiontype"
            ),
            nullable=False,
        ),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_activation_code")),
    )
    op.create_table(
        "admin_user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(length=100), nullable=False),
        sa.Column("password", sa.String(length=255), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column(
            "can_create_admins", sa.Boolean(), server_default="0", nullable=False
        ),
        sa.Column("can_export", sa.Boolean(), server_default="0", nullable=False),
        sa.Column("can_delete", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_edit", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_add", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_view_files", sa.Boolean(), server_default="0", nullable=True),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_admin_user")),
        sa.UniqueConstraint("email", name=op.f("uq_admin_user_email")),
    )
    op.create_table(
        "bot_settings",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("price_one_calendar_ru", sa.Float(), nullable=False),
        sa.Column("price_seven_calendars_ru", sa.Float(), nullable=False),
        sa.Column("price_unlimited_ru", sa.Float(), nullable=False),
        sa.Column("price_one_calendar_en", sa.Float(), nullable=False),
        sa.Column("price_seven_calendars_en", sa.Float(), nullable=False),
        sa.Column("price_unlimited_en", sa.Float(), nullable=False),
        sa.Column("price_one_calendar_uk", sa.Float(), nullable=False),
        sa.Column("price_seven_calendars_uk", sa.Float(), nullable=False),
        sa.Column("price_unlimited_uk", sa.Float(), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_bot_settings")),
    )
    op.create_table(
        "category",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title_ru", sa.String(length=255), nullable=False),
        sa.Column("title_en", sa.String(length=255), nullable=False),
        sa.Column("title_uk", sa.String(length=255), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_category")),
    )
    op.create_table(
        "user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("telegram_id", sa.BigInteger(), nullable=False),
        sa.Column("username", sa.String(length=255), nullable=False),
        sa.Column(
            "check_tasks_time", sa.Time(), server_default="19:00", nullable=False
        ),
        sa.Column("get_tasks_time", sa.Time(), server_default="18:00", nullable=False),
        sa.Column(
            "lang_code",
            sa.Enum("ru", "en", "uk", name="langcode"),
            server_default="ru",
            nullable=False,
        ),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_user")),
        sa.UniqueConstraint("telegram_id", name=op.f("uq_user_telegram_id")),
    )
    op.create_table(
        "bill",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("summ", sa.Float(), nullable=False),
        sa.Column(
            "currency", sa.Enum("ru", "en", "uk", name="currency"), nullable=False
        ),
        sa.Column("invoice_id", sa.String(length=50), nullable=True),
        sa.Column(
            "status",
            sa.Enum("paid", "waiting_payment", "payment_failed", name="paymentstatus"),
            server_default="waiting_payment",
            nullable=False,
        ),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["user_id"], ["user.id"], name=op.f("fk_bill_user_id_user")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_bill")),
    )
    op.create_table(
        "calendar",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title_ru", sa.String(length=255), nullable=False),
        sa.Column("title_en", sa.String(length=255), nullable=False),
        sa.Column("title_uk", sa.String(length=255), nullable=False),
        sa.Column("description_ru", sa.TEXT(), nullable=True),
        sa.Column("description_en", sa.TEXT(), nullable=True),
        sa.Column("description_uk", sa.TEXT(), nullable=True),
        sa.Column("final_message_ru", sa.TEXT(), nullable=False),
        sa.Column("final_message_en", sa.TEXT(), nullable=False),
        sa.Column("final_message_uk", sa.TEXT(), nullable=False),
        sa.Column("category_id", sa.Integer(), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["category_id"],
            ["category.id"],
            name=op.f("fk_calendar_category_id_category"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_calendar")),
    )
    op.create_table(
        "subscription",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column(
            "status",
            sa.Enum("active", "expired", name="subscriptionstatus"),
            server_default="active",
            nullable=False,
        ),
        sa.Column(
            "subscription_type",
            sa.Enum(
                "one_calendar", "seven_calendars", "unlimited", name="subscriptiontype"
            ),
            nullable=False,
        ),
        sa.Column("activation_code_id", sa.Integer(), nullable=True),
        sa.Column(
            "start_date", sa.DateTime(), server_default=sa.text("now()"), nullable=False
        ),
        sa.Column(
            "notify_sent", sa.Boolean(), server_default=sa.text("false"), nullable=False
        ),
        sa.Column("end_date", sa.DateTime(), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["activation_code_id"],
            ["activation_code.id"],
            name=op.f("fk_subscription_activation_code_id_activation_code"),
        ),
        sa.ForeignKeyConstraint(
            ["user_id"], ["user.id"], name=op.f("fk_subscription_user_id_user")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_subscription")),
    )
    op.create_table(
        "calendar_task",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("day", sa.Integer(), nullable=False),
        sa.Column("task_text_ru", sa.TEXT(), nullable=False),
        sa.Column("task_text_en", sa.TEXT(), nullable=False),
        sa.Column("task_text_uk", sa.TEXT(), nullable=False),
        sa.Column("calendar_id", sa.Integer(), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["calendar_id"],
            ["calendar.id"],
            name=op.f("fk_calendar_task_calendar_id_calendar"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_calendar_task")),
    )
    op.create_table(
        "user_calendar",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column(
            "status",
            sa.Enum("active", "done", name="usercalendarstatus"),
            server_default="active",
            nullable=False,
        ),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("subscription_id", sa.Integer(), nullable=False),
        sa.Column("calendar_id", sa.Integer(), nullable=False),
        sa.Column("successful_tasks", sa.Integer(), server_default="0", nullable=False),
        sa.Column("tasks_sent", sa.Integer(), server_default="0", nullable=False),
        sa.Column(
            "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["calendar_id"],
            ["calendar.id"],
            name=op.f("fk_user_calendar_calendar_id_calendar"),
        ),
        sa.ForeignKeyConstraint(
            ["subscription_id"],
            ["subscription.id"],
            name=op.f("fk_user_calendar_subscription_id_subscription"),
        ),
        sa.ForeignKeyConstraint(
            ["user_id"], ["user.id"], name=op.f("fk_user_calendar_user_id_user")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_user_calendar")),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("user_calendar")
    op.drop_table("calendar_task")
    op.drop_table("subscription")
    op.drop_table("calendar")
    op.drop_table("bill")
    op.drop_table("user")
    op.drop_table("category")
    op.drop_table("bot_settings")
    op.drop_table("admin_user")
    op.drop_table("activation_code")
    # ### end Alembic commands ###
